package com.eascs.spider.hr.user.interceptor;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.eascs.spider.hr.user.service.UserService;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;

public class UserMockInterceptorAdapter extends HandlerInterceptorAdapter {
	@Inject
	private UserService userService;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		com.eascs.spider.hr.user.entity.User adminUser = userService.getUserByLoginName("muwang.zheng");
		User user = new User();
		user.setCode(adminUser.getCode());
		user.setAccount(adminUser.getLoginName());
		user.setCname(adminUser.getName());
		user.setEmail(adminUser.getEmail());
		user.setMobile(adminUser.getMobile());
		user.setPhone(adminUser.getPhone());
		user.setSuperAdministrator(true);
		UserHolder.setUser(user);
		return super.preHandle(request, response, handler);
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		UserHolder.clear();
		super.afterCompletion(request, response, handler, ex);
	}

}
